<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateActivityGroupsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //我们的活动允许多个单位一起主办，一般来说，可以由其中某一个单位在管理后台发起活动
        //然后通过引入其它单位的code(user_groups表的code字段，用来唯一标识本平台的所有group)，从而加入其它合办单位
        Schema::create('activity_groups', function (Blueprint $table) {
            $table->bigIncrements('id')->unsigned();

            $table->bigInteger('group_id')->unsigned()->comment('活动组织单位id');
            $table->foreign('group_id')->references('id')->on('user_groups');

            $table->integer('activity_id')->unsigned()->comment('活动id');
            $table->foreign('activity_id')->references('id')->on('activities');

            $table->tinyInteger('major_flag')->default(0)->nullable()->comment('是否主办单位：1=是，0=否');

            $table->tinyInteger('sort_order')->unsigned()->comment('活动组织单位排序号');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('activity_groups', function ($table) {
            $table->dropForeign(['activity_id']);
            $table->dropForeign(['group_id']);
        });
        Schema::dropIfExists('activity_groups');
    }
}
